package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.ReportService;
import com.itheima.health.vo.EChartsReportVo;
import com.itheima.health.vo.ReportVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 运营数据统计控制器
 *
 * @author Administrator
 * @date 2023/4/27
 */
@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

    /**
     * 运营统计
     */
    @Autowired
    private ReportService reportService;

    /**
     * 会员
     */
    @Autowired
    private MemberService memberService;

    /**
     * 订单
     */
    @Autowired
    private OrderService orderService;

    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData() {
        ReportVo reportAll = reportService.findAll();
        return reportAll == null ? new Result(false, MessageConst.GET_BUSINESS_REPORT_FAIL)
                : new Result(true, MessageConst.GET_BUSINESS_REPORT_SUCCESS, reportAll);
    }

    /**
     * 折线统计图请求方法
     *
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport() {
        log.info("当前为折线图统计数据");
        //封装数据展示给前端
        EChartsReportVo reportVo = memberService.getMemberReport();
        return reportVo != null ? new Result(true, MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS, reportVo) : new Result(false, MessageConst.GET_MEMBER_NUMBER_REPORT_FAIL);
    }

    /**
     * 饼状图查询数据
     *
     * @return
     */

    @GetMapping("/getSetmealReport")
    public Result getSetmealReport() {
        log.info("当前为饼状图统计数据");
        //调用
        EChartsReportVo reportVo = orderService.getSetmealReport();
        return reportVo != null ? new Result(true, MessageConst.GET_SETMEAL_COUNT_REPORT_SUCCESS, reportVo) : new Result(false, MessageConst.GET_SETMEAL_COUNT_REPORT_FAIL);
    }

    /**
     * 运营数据导出
     */
    @GetMapping("/exportBusinessReport")
    public Result exportBusinessReport() throws IOException {
        return reportService.export();
    }


}
